package simultaneously.base;

/**
 * Created by 焕滨 on 2016/3/12.
 */
class Sleeper extends Thread{
    private int duration;
    public Sleeper(String name,int sleepTime){
        super(name);
        this.duration = sleepTime;
        start();
    }
    public void run(){
        try{
            sleep(duration);
        }catch(InterruptedException e){
            e.printStackTrace();
        }
        System.out.println(getName() + "has awakened");
    }
}

class Joiner extends Thread{
    private Sleeper sleeper;
    public Joiner(String name,Sleeper sleeper){
        super(name);
        this.sleeper = sleeper;
        start();
    }

    public void run(){
        try {
            sleeper.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(getName() + " join Completed");
    }
}

public class Joining {

    public static void main(String[] args){
        Sleeper sleepy = new Sleeper("Sleepy",1500),
                grumpy = new Sleeper("Grumpy",1500);
        new Joiner("Dopey",sleepy);
        new Joiner("Doc",grumpy);
        grumpy.interrupt();
    }
}
